home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC / src / dlgclr.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  3.8 KB  |  153 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12. #if !defined(_WIN32_WCE_NO_COLORDLG)
  13.  
  14. #ifdef AFX_AUX_SEG
  15. #pragma code_seg(AFX_AUX_SEG)
  16. #endif
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. #define new DEBUG_NEW
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // Choose Color dialog
  27.  
  28. class _AFX_COLOR_STATE : public CNoTrackObject
  29. {
  30. public:
  31.     // custom colors are held here and saved between calls
  32.     COLORREF m_crSavedCustom[16];
  33.  
  34.     _AFX_COLOR_STATE();
  35. };
  36.  
  37. _AFX_COLOR_STATE::_AFX_COLOR_STATE()
  38. {
  39.     // custom colors are initialized to white
  40.     for (int i = 0; i < _countof(m_crSavedCustom); i++)
  41.         m_crSavedCustom[i] = RGB(255, 255, 255);
  42. }
  43.  
  44. #ifndef _AFX_NO_GRAYDLG_SUPPORT
  45. BEGIN_MESSAGE_MAP(CColorDialog, CCommonDialog)
  46.     //{{AFX_MSG_MAP(CColorDialog)
  47.     ON_WM_CTLCOLOR()
  48.     //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50. #endif //!_AFX_NO_GRAYDLG_SUPPORT
  51.  
  52. EXTERN_PROCESS_LOCAL(_AFX_COLOR_STATE, _afxClrState)
  53.  
  54. CColorDialog::CColorDialog(COLORREF clrInit, DWORD dwFlags,
  55.     CWnd* pParentWnd) : CCommonDialog(pParentWnd)
  56. {
  57.     memset(&m_cc, 0, sizeof(m_cc));
  58.     m_nIDHelp = AFX_IDD_COLOR;
  59.  
  60.     m_cc.lStructSize = sizeof(m_cc);
  61.     m_cc.lpCustColors = GetSavedCustomColors();
  62.     m_cc.Flags = dwFlags | CC_ENABLEHOOK;
  63.     if (!afxData.bWin4 && AfxHelpEnabled())
  64.         m_cc.Flags |= CC_SHOWHELP;
  65.     m_cc.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc;
  66.  
  67.     if ((m_cc.rgbResult = clrInit) != 0)
  68.         m_cc.Flags |= CC_RGBINIT;
  69. }
  70.  
  71. int CColorDialog::DoModal()
  72. {
  73.     ASSERT_VALID(this);
  74.     ASSERT(m_cc.Flags & CC_ENABLEHOOK);
  75.     ASSERT(m_cc.lpfnHook != NULL); // can still be a user hook
  76.  
  77.     m_cc.hwndOwner = PreModal();
  78.     int nResult = ::ChooseColor(&m_cc);
  79.     PostModal();
  80.     return nResult ? nResult : IDCANCEL;
  81. }
  82.  
  83. BOOL CColorDialog::OnColorOK()
  84. {
  85.     ASSERT_VALID(this);
  86.     // Do not call Default() if you override
  87.     return FALSE;
  88. }
  89.  
  90. #if !defined(_WIN32_WCE)
  91. void CColorDialog::SetCurrentColor(COLORREF clr)
  92. {
  93.     ASSERT_VALID(this);
  94.     ASSERT(m_hWnd != NULL);
  95.  
  96.     SendMessage(_afxMsgSETRGB, 0, (DWORD)clr);
  97. }
  98. #endif // _WIN32_WCE
  99.  
  100. COLORREF* PASCAL CColorDialog::GetSavedCustomColors()
  101. {
  102.     return &_afxClrState->m_crSavedCustom[0];
  103. }
  104.  
  105. // The color tracker in the COMMDLG.DLL can't handle gray backgrounds,
  106. //  so we force the default with this override.
  107.  
  108. #ifndef _AFX_NO_GRAYDLG_SUPPORT
  109. HBRUSH CColorDialog::OnCtlColor(CDC*, CWnd*, UINT)
  110. {
  111.     return (HBRUSH)Default();
  112. }
  113. #endif //!_AFX_NO_GRAYDLG_SUPPORT
  114.  
  115. ////////////////////////////////////////////////////////////////////////////
  116. // CColorDialog diagnostics
  117.  
  118. #ifdef _DEBUG
  119. void CColorDialog::Dump(CDumpContext& dc) const
  120. {
  121.     CDialog::Dump(dc);
  122.  
  123.     dc << "m_cc.hwndOwner = " << (UINT)m_cc.hwndOwner;
  124.     dc << "\nm_cc.rgbResult = " << (LPVOID)m_cc.rgbResult;
  125.     dc << "\nm_cc.Flags = " << (LPVOID)m_cc.Flags;
  126.     dc << "\nm_cc.lpCustColors ";
  127.  
  128.     for (int iClr = 0; iClr < 16; iClr++)
  129.         dc << "\n\t" << (LPVOID)m_cc.lpCustColors[iClr];
  130.  
  131.     if (m_cc.lpfnHook == (COMMDLGPROC)_AfxCommDlgProc)
  132.         dc << "\nhook function set to standard MFC hook function";
  133.     else
  134.         dc << "\nhook function set to non-standard hook function";
  135.  
  136.     dc << "\n";
  137. }
  138. #endif //_DEBUG
  139.  
  140. #ifdef AFX_INIT_SEG
  141. #pragma code_seg(AFX_INIT_SEG)
  142. #endif
  143.  
  144. IMPLEMENT_DYNAMIC(CColorDialog, WCE_IF(CCommonDialog,CDialog))
  145.  
  146. #pragma warning(disable: 4074)
  147. #pragma init_seg(lib)
  148.  
  149. PROCESS_LOCAL(_AFX_COLOR_STATE, _afxClrState)
  150.  
  151. ////////////////////////////////////////////////////////////////////////////
  152. #endif // _WIN32_WCE_NO_COLORDLG
  153.